home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 July
/
EnigmA AMIGA RUN 09 (1996)(G.R. Edizioni)(IT)[!][issue 1996-07 & 08][EARSAN CD VIII].iso
/
earcd
/
util3
/
wat.lha
/
WAT
next >
Wrap
Text File
|
1996-06-03
|
9KB
|
188 lines
/* What?! Another Timer?! Version 1.00 */
/* Copyright © Michael Tanzer 1996 */
/* See additional notices in accompanying documentation */
blanks = 0 /* Number of blank lines at the top of the window. */
/* If you use a screen text font that is larger than */
/* 9 pixels in height, you may need to increase this */
/* value (by 1 or 2) for cosmetic purposes. */
arg nport . /* Notify port */
/* Make sure the necessary functions are available */
if ~show('l','rexxsupport.library') then
call addlib('rexxsupport.library',0,-30)
if ~show('l','rexxarplib.library') then
call addlib('rexxarplib.library',0,-30)
signal on syntax
/* Run WAT asynchronously */
w = getclip('WAT') /* See if we've been here */
if w~=1 then do /* Nope, initialise */
parse source mode . /* COMMAND or FUNCTION? */
w = getnport(nport) /* Go verify port name */
if w~=1 then do /* Handle error */
if mode='COMMAND' then exit w
return 0
end
call setclip('WAT',1) /* Mark the trail */
address arexx 'WAT' nport /* Run asynchronously */
if mode='COMMAND' then exit
return 1
end
call setclip('WAT') /* Clear flag */
/* Get name for control port */
cport = nport'CTL'
if showlist('p',cport) then call exit(cport)
/* Set some rather important variables */
cfgfile = 'S:WAT.config'
idcmp = 'closewindow+gadgetup+menupick'
flags = 'windowclose+windowdrag+windowdepth'
xchar = 8 /* Pixels / col */
ychar = 9 /* Pixels / row */
yoff = ychar*blanks /* Blank lines */
wx = 0 /* Window left */
wy = 0 /* Window top */
ww = 168 /* Window width */
wh = 59+yoff /* Window height */
stx = 18 /* START left */
sty = 14+yoff /* START top */
spx = 114 /* STOP left */
spy = 14+yoff /* STOP top */
/* Read config file */
w = open('input',cfgfile,'r') /* Open config file as input */
if w=1 then do /* Proceed if file found */
w = readln('input') /* Read 1st record */
do while ~eof('input') /* Loop through rest of file */
interpret w /* Interpret this record */
w = readln('input') /* Read next record */
end
call close 'input' /* Close config file */
end
/* Set up host environment, window, etc. */
startsecs = time('s') /* Set start time */
stopsecs = time('s') /* Set stop time */
call openport(nport) /* Open notify port */
address arexx "'call createhost("cport","nport")'"/* Open control port */
address command 'WAITFORPORT' cport /* Note: fall through on error */
call openw /* Go open new window */
call showtime /* Go show the time */
flags = flags'+activate' /* Adjust for preferences */
/* Main control loop */
halt: do forever /* Top of main control loop */
signal on halt /* HI causes return to top */
trace 'b' /* Continue in spite of TS */
call waitpkt(nport) /* Wait for some action */
pkt = getpkt(nport) /* Retrieve packet */
if pkt=='00000000'x then iterate /* Caused by TS */
message = getarg(pkt) /* Retrieve message */
call reply(pkt,0) /* Acknowledge message */
action = upper(word(message,1)) /* Isolate 1st word of msg */
select /* Respond as required */
when action=='QUIT' then leave /* QUIT chosen from menu */
when action=='CLOSEWINDOW' then leave /* Window closed */
when action=='START' then do /* START gadget */
startsecs = time('s') /* Reset start time */
stopsecs = startsecs /* Reset stop time */
end /* START */
when action=='STOP' then do /* STOP gadget */
stopsecs = time('s') /* Get stop time */
end /* STOP */
when action=='SPREF' then do /* SAVE PREFS chosen from menu */
if words(message)>2 then do /* Check for window position */
wx = word(message,2) /* Save window x */
wy = word(message,3) /* Save window y */
end
w = statef(cfgfile) /* See if cfg file exists */
if w='' then call delete cfgfile /* If so, delete it */
call open 'output',cfgfile,'w' /* Open config file as output*/
if result then do /* Proceed if open ok... */
w = 'wx =' wx /* Window left */
call writeln 'output',w
w = 'wy =' wy /* Window top */
call writeln 'output',w
call close 'output' /* Close output file */
msg = 'Preferences saved.' /* Build success message */
end
else msg = 'Unable to write\'cfgfile/* ...or build error message */
call postmsg(0,0,msg) /* Post the message */
call delay 100 /* Wait a couple seconds */
call postmsg() /* Clear the message */
iterate /* Bypass refresh */
end /* SPREF */
otherwise iterate /* Ignore unknown actions */
end /* select */
call showtime /* Show the elapsed time */
end /* Main control loop */
/* Clean up and get out */
syntax: signal off syntax /* Clear for next two calls */
call exit(cport) /* Close window, remove host */
call closeport(nport) /* Close notify port */
exit /* Ride off into the sunset */
showtime: /* Show the elapsed time */
if stopsecs>=startsecs then, /* Get elapsed time */
elapsed = stopsecs-startsecs
else elapsed = stopsecs+86400-startsecs /* Handle midnight crossing */
text = left('\',blanks,'\') ||, /* Adjust for large font */
'\Start 'gettime(startsecs) ||, /* Get start time */
'\Stop 'gettime(stopsecs) ||, /* Get stop time */
'\Elapsed 'gettime(elapsed) /* Get elapsed time */
call windowtext(cport,text) /* Write time */
return
gettime:
arg s /* Get seconds */
hh = right(s%3600,2,'0') /* Get hours */
w = s//3600
mm = right(w%60,2,'0') /* Get minutes */
w = w//60
ss = right(w%1,2,'0') /* Get seconds */
time = hh':'mm':'ss /* Format time */
return time
openw: /* Open a window */
w = screencols('Workbench')
if wx+ww>w then wx = w-ww
w = screenrows('Workbench')
if wy+wh>w then wy = w-wh
call openwindow(cport,wx,wy,ww,wh,idcmp,flags,nport)
call addmenu(cport,left(nport,8))
call additem(cport,'Save prefs ','spref %f %e')
call additem(cport,'Quit ','quit')
call addgadget(cport,stx,sty,'start','Start','start')
call addgadget(cport,spx,spy,'stop','Stop','stop')
call setitem(cport,0,1,0,'on')
return
/* Get notify port name */
getnport:
if nport='HELP' | nport='?' then do
say 'Format: WAT <portname>'
exit
end
if words(nport)=0 then do
nport = 'WAT'
w = 1
if showlist('p','WAT') then do forever
nport = 'WAT'w
if ~showlist('p',nport) then leave
w = w+1
end
end
else do
if showlist('p',nport) then do
say 'Port' nport 'already in use.'
return 99
end
end
return 1